package cn.brondfish.icedfish.database.system;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;
import androidx.sqlite.db.SupportSQLiteDatabase;

import java.io.File;

import cn.brondfish.icedfish.database.system.converters.DataConverters;
import cn.brondfish.icedfish.database.system.dao.SysUserDao;
import cn.brondfish.icedfish.database.system.dao.SysUserPermissionDao;
import cn.brondfish.icedfish.database.system.dao.SysUserRoleDao;
import cn.brondfish.icedfish.database.system.entity.SysUser;
import cn.brondfish.icedfish.database.system.entity.SysUserPermission;
import cn.brondfish.icedfish.database.system.entity.SysUserRole;
import cn.brondfish.icedfish.framework.util.BF_DeviceUniqueID;

@TypeConverters(value = { DataConverters.class })
@Database(entities = {SysUser.class, SysUserPermission.class ,SysUserRole.class},version = 1,exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
    private static AppDatabase appDatabase;
    public static final String db_filename = "database/app_database.db";

    public static AppDatabase getDatabase(final Context context) {
        if (appDatabase == null) {
            synchronized (AppDatabase.class) {
                if (appDatabase == null) {
                    appDatabase = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, context.getApplicationContext().getFilesDir()+File.separator+db_filename)
                            .build();
                }
            }
        }
        return appDatabase;
    }

    public abstract SysUserDao sysUserDao();

    public abstract SysUserPermissionDao userPermissionDao();

    public abstract SysUserRoleDao userRoleDao();

}
